<template>
  <div>
    <ul v-show="this.user">
      <li
        class="item"
        v-for="(item, index) in $store.state.userLabellData.filter(item=>item.user==this.user)"
        :key="index"
        :id="item.Id"
      >
        <div class="tag">
          <div class="info-box">
            <a>
              <div
                class="lazy thumb thumb loaded"
                style="background-size: contain;"
              >
                <img :src="item.tag.icon" alt="" />
              </div>
              <div class=" title">{{ item.tag.tag_name }}</div>
            </a>
            <div class="meta-box">
              <div class="meta subscribe">{{ item.tag.post_article_count }} 关注</div>
              <div class="meta article">{{ item.tag.concern_user_count  }} 文章</div>
            </div>
          </div>
          <div class="action-box">
            <button
              class="subscribe-btn"
              @click.prevent="subscribed(item)"
            >
              <span>已关注</span>
            </button>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: localStorage.getItem("isLogin"),
    };
  },
  created(){
    this.$store.dispatch('getUserData')
  },
  methods: {
    //点击关注
    subscribed(item){
      console.log(item)
      this.$store.dispatch("addLabel", { user: this.user ,item});
    }
  },
}
</script>

<style scoped lang="scss" >
ul {
  width: 100%;
  padding: 20px 8px;
  li {
    width: 25%;
    display: inline-block;
    margin-bottom: 15.6px;
    padding: 0 8.4px;

    .tag {
      width: 100%;
      background-color: #fff;
      display: inline-block;
      border: 1px solid #f1f1f1;
      transition: border-color 0.3s;
      text-align: center;
      padding: 18px 0;

      .info-box {
        .thumb {
          img {
            height: 32px;
          }
        }
        .title{
          margin: 8px 0;
        }
      }

      .meta-box {
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 14px;
        color: #909090;

        .meta {
          line-height: 24px;
        }

        .meta.article {
          margin-left: 9.6px;
        }
      }

      .subscribe-btn {
        border: 1px solid #37c700;
        background-color: #fff;
        color: #fff;
        margin: 12px auto;
        font-size: 14.4px;
        background-color: #37c700;
      }

      .subscribe-btn.subscribed {
        background-color: #37c700;
        color: #fff;
      }
    }
  }
}
</style>